﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using CodeStash.Common.DataAccess.Repository;
using CodeStash.Common.DataAccess.EntityFramework;
using CodeStash.Common.Encryption;

namespace CodeStash.IntegrationTests
{
    [TestFixture]
    public class EncryptionTests
    {
        private string passPhrase = "Pas5pr@se";        // can be any string
        private string saltValue = "s@1tValue";        // can be any string
        private string hashAlgorithm = "SHA1";             // can be "MD5"
        private int passwordIterations = 2;                  // can be any number
        private string initVector = "@1B2c3D4e5F6g7H8"; // must be 16 bytes
        private int keySize = 256;                // can be 192 or 128


        [TestCase(false,"Hello, World!")]
        [TestCase(false, "sacha.barber@gmail.com")]
        [TestCase(true, "")]
        public void EncryptDecrypt_PlainText_Test(bool isGuid, string plainText)
        {
            string textToEncrypt = isGuid ? Guid.NewGuid().ToString() : plainText;

            string cipherText = RijndaelSimple.Encrypt(textToEncrypt,
                                                        passPhrase,
                                                        saltValue,
                                                        hashAlgorithm,
                                                        passwordIterations,
                                                        initVector,
                                                        keySize);

            string decryptedText = RijndaelSimple.Decrypt(cipherText,
                                                    passPhrase,
                                                    saltValue,
                                                    hashAlgorithm,
                                                    passwordIterations,
                                                    initVector,
                                                    keySize);

            Assert.AreEqual(textToEncrypt, decryptedText);
        }
    }
}
